home *** CD-ROM | disk | FTP | other *** search
/ Power Hacker 2003 / Power_Hacker_2003.iso / Exploit and vulnerability / w00w00 / sectools / SRS / client / src / debug.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-01-12  |  1.2 KB  |  50 lines

  1. #include "headers.h" /* has all the important stuff */
  2.  
  3. /* function to output debugging information */
  4. void debug(char *fmt, ...)
  5. {
  6.    va_list args;
  7.    const int headlen = strlen("[DEBUG (pid XXXXX)]: ") + 1;
  8.  
  9.    char debugbuf[MAXREADSIZE];
  10.    char bigbuf[MAXREADSIZE + headlen];
  11.  
  12.  
  13.    if (debugging != 1) return;
  14.  
  15.    memset(bigbuf, 0, sizeof(bigbuf));
  16.    memset(debugbuf, 0, sizeof(debugbuf));
  17.  
  18.    va_start(args, fmt);
  19.    (void)vsnprintf(debugbuf, sizeof(debugbuf) - 1, fmt, args);
  20.    va_end(args);
  21.  
  22.    debugbuf[sizeof(debugbuf)-1] = '\0';
  23.  
  24.    if (((debugbuf[0] == '\n') || (debugbuf[0] == '\0')) && 
  25.        (isprint((int)debugbuf[1]) == 0)) return;
  26.  
  27.    if (debugging == 1)
  28.    {
  29.       if (strncmp(debugbuf, "[ERROR", 6) != 0)
  30.       {
  31.          (void)printf("[DEBUG (pid %d)]: %s", (int)getpid(), debugbuf);
  32.  
  33.          if (dblogfd <= 0) return;
  34.  
  35.          snprintf(bigbuf, sizeof(bigbuf)-1, "[DEBUG (pid %d)]: %s", 
  36.                   (int)getpid(), debugbuf);
  37.          
  38.          (void)write(dblogfd, bigbuf, strlen(bigbuf));
  39.       }
  40.  
  41.       else
  42.       {
  43.          (void)printf("%s", debugbuf);
  44.  
  45.          if (dblogfd <= 0) return;
  46.          (void)write(dblogfd, debugbuf, strlen(debugbuf));
  47.       }
  48.    }
  49. }
  50.